package com.river.springbootdemo.thinkingjava.StringOperation;

import java.util.ArrayList;
import java.util.List;

/**
 * 如何toString打印对象的内存地址
 *
 */
public class InfiniteRecursion {
    @Override
    public String toString() {
//        return "InfiniteRecursion address: "+this.toString()+"\n";//这里会发生无限递归调用 报错java.lang.StackOverflowError
        return "InfiniteRecursion address: " + super.toString() + "\n";
    }

    public static void main(String[] args) {
        List<InfiniteRecursion> infiniteRecursionList = new ArrayList<>();
        for (int i = 0; i < 10; i++)
            infiniteRecursionList.add(new InfiniteRecursion());
        System.out.println(infiniteRecursionList);

    }
}
